<template>
  <div class="dashboard-container">
    <div class="filter-container">
      <el-row :gutter="10" style="width:100%">
        <el-col :span="4">
          <el-input
            v-model="listQuery.trans_no"
            placeholder="交易号"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="listQuery.pay_name"
            placeholder="付款人"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>

        <el-col :span="4">
          <el-date-picker
            v-model="listQuery.created"
            style="width: 100%;"
            type="datetimerange"
            range-separator="~"
            value-format="yyyy-MM-dd HH:mm:ss"
            start-placeholder="创建开始日期"
            end-placeholder="创建结束日期"
            :default-time="['00:00:00', '23:59:59']"
          />
        </el-col>
        <el-col :span="6">
          <div>
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="reloadList"
            >搜索</el-button>
            <el-button
              class="filter-item"
              style="margin-left: 10px;"
              icon="el-icon-download"
              type="primary"
              @click="download"
            >
              导出
            </el-button>
          </div>

        </el-col>
      </el-row>
    </div>
    <div style="padding:0 20px">

      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        height="calc(100vh - 200px)"
        style="width: 100%;"
        size="mini"
        border
        tooltip-effect="dark"
        :header-cell-style="{ background: '#eaf1fd', color: '#333' }"
      >
        <el-table-column
          label="充值日期"
          width="250px"
          prop="created"
        />
        <el-table-column
          label="用户名称"
          min-width="150px"
          prop="user.username"
        />
        <el-table-column
          label="充值金额"
          width="150px"
          prop="amount"
        />
        <el-table-column
          label="金额类型"
          width="100px"
        >
          <template slot-scope="{ row }">
            <div>
              <span v-if="row.account_type == 1">余额</span>
              <span v-if="row.account_type == 2">授信</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="充值方式"
          width="100px"
        >
          <template slot-scope="{ row }">
            <div>
              <span v-if="row.type == 1">线下支付</span>
              <span v-if="row.type == 2">余额还款</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="付款方式"
          width="100px"
        >
          <template slot-scope="{ row }">
            <div>
              <span v-if="row.pay_type == 1">转账</span>
              <span v-if="row.pay_type == 2">现金</span>
            </div>
          </template>

        </el-table-column>

        <el-table-column
          label="交易号"
          min-width="250px"
          prop="trans_no"
        />
        <el-table-column
          label="付款人"
          width="150px"
          prop="pay_name"
        />
        <el-table-column
          label="付款银行账号"
          width="200px"
          prop="bank_account"
        />
        <el-table-column
          label="充值状态"
          width="100px"
        >
          <template slot-scope="{ row }">
            <div>
              <span v-if="row.status == 0">待审核</span>
              <span v-if="row.status == 1" style="color:blue">审核通过</span>
              <span v-if="row.status == 2" style="color:red">审核未通过</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="拒绝原因"
          width="200px"
          prop="remark"
        />
        <el-table-column
          label="转账凭证"
          width="150px"
        >
          <template slot-scope="{ row }">
            <div>
              <div v-if="row.pay_img">
                <el-image
                  style="width: 50px; height: 50px"
                  :src="row.pay_img"
                  :preview-src-list="[row.pay_img]"
                />
              </div>

            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="审核人"
          width="100px"
          prop="operator"
        />
        <el-table-column
          label="审核时间"
          width="150px"
          prop="updated"
        />
        <el-table-column
          label="操作"
          align="right"
          width="180"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button
              v-if="row.status == 0"
              size="mini"
              type="primary"
              @click="verify(row,1)"
            >
              通过
            </el-button>
            <el-button
              v-if="row.status == 0"
              type="danger"
              @click="verify(row,2)"
            >
              拒绝
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </div>
    <!-- <Detial :detial="detial" :status="status" :visible="visible" @update="closeDraw" @reload="reloadList" /> -->
  </div>
</template>

<script>
import { rechargeList, rechargeCheck, exportRechargeList } from '@/api/finance/index'

import Pagination from '@/components/Pagination' // secondary package based on el-pagination
// import Detial from './components/flightDetial.vue'

export default {
  name: 'Dashboard',
  components: {
    Pagination
    // Detial
  },
  data() {
    return {
      data_arr: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        trans_no: '',
        pay_name: '',
        created: ''

      },
      visible: false,
      status: 1,
      id: '',
      detial: {},
      message: ''
    }
  },
  computed: {
  },
  created() {
    this.getList()
  },
  methods: {
    closeDraw() {
      this.visible = false
    },
    addNews() {
      this.status = 1
      this.visible = true
    },
    edit(row) {
      this.detial = { ...row }
      this.status = 2
      this.visible = true
    },
    verify(row, status) {
      if (status === 1) {
        this.message = '确认审核通过?'
        this.$confirm(this.message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          rechargeCheck({
            id: row.id,
            status: status
          }).then(res => {
            this.$message({
              type: 'success',
              message: res.msg
            })
            this.getList()
          })
        }).catch(() => {

        })
      } else {
        this.$prompt('请输入拒绝原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({ value }) => {
          rechargeCheck({
            id: row.id,
            status: status,
            remark: value
          }).then(res => {
            this.$message({
              type: 'success',
              message: res.msg
            })
            this.getList()
          })
        }).catch(() => {

        })
      }
    },
    reloadList() {
      this.listQuery.page = 1
      this.visible = false
      this.getList()
    },
    getList() {
      this.listLoading = true
      rechargeList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    download() {
      exportRechargeList(this.listQuery).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
      })
    }
  }
}
</script>
<style scoped>
.filter-container{
  padding:20px 20px 10px;
}

.upload-demo{
  margin: 20px 0 10px;
}
</style>
